package com.ljyanimo.controller;


import com.ljyanimo.response.ServerResponse;
import com.ljyanimo.service.ISysMenuService;
import com.ljyanimo.utils.ShiroUtils;
import com.ljyanimo.vo.NavigationMenuVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author
 * @since 2020-10-16
 */
@Controller
@RequestMapping("/sys-menu")
public class SysMenuController {

    @Autowired
    private ISysMenuService iSysMenuService;

    @Autowired
    private ShiroUtils shiroUtils;

    /**
     * 根据当前登录用户查询左侧菜单
     * @return
     */
    @PostMapping("/menu")
    @ResponseBody
    public ServerResponse selectMenuByUserId(){
        List<NavigationMenuVo> navigationMenuVos = iSysMenuService.selectMenuByUserId(shiroUtils.getUserId());
        return ServerResponse.createBySuccess(navigationMenuVos);
    }

    /**
     * 添加角色显示的树结构
     * @return
     */
    @PostMapping("/tree")
    @ResponseBody
    public ServerResponse tree(){
        return ServerResponse.createBySuccess(iSysMenuService.tree());
    }

    /**
     * 编辑角色显示的树结构
     * @return
     */
    @PostMapping("/treeEdit/{id}")
    @ResponseBody
    public ServerResponse treeEdit(@PathVariable("id") Integer id){
        return ServerResponse.createBySuccess(iSysMenuService.treeEdit(id));
    }

    @GetMapping("/test")
    @ResponseBody
    @RequiresPermissions("sys:test")
    public ServerResponse test(){
        return ServerResponse.createBySuccess("测试访问成功");
    }

    /**
     * 表格数据
     * @return
     */
    @ResponseBody
    @GetMapping("/list")
    public ServerResponse selectListMenu(){
        return ServerResponse.createBySuccess(iSysMenuService.selectListMenu());
    }

    /**
     * 菜单列表页面
     * @return
     */
    @GetMapping("/listPage")
    public String menuPage(){
        return "menu/list";
    }

}
